<?php
abstract class BackendActiveRecord extends CActiveRecord
{
    protected function beforeSave()
    {
        if(null !== Yii::app()->user){
            $id = Yii::app()->user->id;
        }else{
            $id = 1;
        }

        if($this->isNewRecord)
        {
            if($this->tableName() === '{{users}}')
            {
                $this->password = md5($this->password);
                $this->avatar = '/images/avatar/noavatar.png';
            }
            $this->create_user_id = $id;
        }
        else
        {
            $this->update_user_id = $id;
            if($this->tableName() === '{{users}}')
            {
                if(strlen($this->avatar) < 14)
                {
                    $this->avatar = '/images/avatar/noavatar.png';
                }
            }

        }
        return parent::beforeSave();

    }
    public function behaviors()
    {
        return array(
            'CTimestampBehavior' => array(
                'class'=>'zii.behaviors.CTimestampBehavior',
                'createAttribute' => 'create_time',
                'updateAttribute' => 'update_time',
                'setUpdateOnCreate' => true,
            )
        );
    }
}